import request from '@/utils/axios'
import type {
  userCode,
  userDataRecords,
  userCodes,
  userRole,
  setRoleData,
  successCode,
} from './type'
enum API {
  ALLUSER_URL = '/admin/acl/user/',
  ADDUSER_URL = '/admin/acl/user/save',
  UPDATEUSER_URL = '/admin/acl/user/update',
  ALLROLEURL = '/admin/acl/user/toAssign/',
  SETROLE_URL = '/admin/acl/user/doAssignRole',
  DELETEUSER_URL = '/admin/acl/user/remove/',
  DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
}
// 获取用户列表信息
export const userList = (page: number, size: number, limt: string) =>
  request.get<any, userCode>(
    API.ALLUSER_URL + `${page}/${size}/?username=${limt}`,
  )
// 新增/修改用户
export const userAddEdit = (data: userDataRecords) => {
  if (data.id) {
    return request.put<any, userCodes>(API.UPDATEUSER_URL, data)
  } else {
    return request.post<any, userCodes>(API.ADDUSER_URL, data)
  }
}
// 获取全部职位以及当前用户已有职位
export const reqAllRole = (userId: number) =>
  request.get<any, userRole>(API.ALLROLEURL + userId)
// 分配职位
export const reqSetUserRole = (data: setRoleData) =>
  request.post<any, successCode>(API.SETROLE_URL, data)
//删除一个账户
export const reqDelUser = (userId: number) =>
  request.delete<any, successCode>(API.DELETEUSER_URL + userId)
// 批量删除
export const reqAllDelUser = (idList: number[]) =>
  request.delete<any, successCode>(API.DELETEALLUSER_URL, { data: idList })
